<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title></title>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/bootstrap.css"/>
    <link rel="stylesheet" type="text/css"
          href="${pageContext.request.contextPath}/css/bootstrap-responsive.css"/>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css"/>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/bootstrap.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/ckform.js"></script>
    <script type="text/javascript" src="${pageContext.request.contextPath}/js/common.js"></script>
    <script src="${pageContext.request.contextPath}/js/jquery.min.js?v=2.1.4"></script>
    <script>
        $(function(){
            getBigCategory();
            $(document).on("click",".subType",function(event){
                var $select=$(this);
                var typeid=$(this).parents("tr").children().eq(0).text();
                $.ajax({
                    url:"${pageContext.request.contextPath}/btype/getSmallList",
                    type:"post",
                    data:{"typeid":typeid},
                    dataType:"json",
                    cache:false,
                    success:function(rs){
                        $select.empty();
                        $(rs).each(function(index,element){
                            var option="<option>"+element.typename+"</option>"
                            $select.append(option);
                        });
                    }
                });
            });

            $(document).on("click",".delbtn",function(event){

                var typeid=$(this).parents("tr").children().eq(0).text();
                $.ajax({
                    url:"${pageContext.request.contextPath}/btype/deleteBigBtype",
                    type:"post",
                    data:{"typeid":typeid},
                    dataType:"json",
                    cache:false,
                    success:function(rs){
                       if(rs.status==200){
                           getBigCategory();
                       }else{
                           alert(rs.msg);
                       }
                    }
                });
            });
        })
        function   getBigCategory(){
            $.ajax({
                url:"${pageContext.request.contextPath}/btype/bigList",
                type:"post",
                dataType:"json",
                cache:false,
                success:function(rs){
                    $("#tbody").empty();
                   $(rs).each(function(index,element){
                       var tr=" <tr>\n" +
                               "<td style='display:none'>"+element.typeid+"</td>"+
                           "            <td>"+element.typename+"</td>\n" +
                           "            <td>"+element.typedes+"</td>\n" +
                           "            <td>\n" +
                           "                <select class='subType'>\n" +
                           "                    <option value=\"2\"/>&nbsp;电影</option>\n" +
                           "                    <option value=\"7\"/>&nbsp;原创</option>\n" +
                           "               </select>\n" +
                           "            </td>\n" +
                           "            <td>\n" +
                           "                <button type=\"submit\"><a href=\"${pageContext.request.contextPath}/btype/subtype_list?typeid="+element.typeid+"\">管理小类</a></button>\n" +
                           "            </td>\n" +
                           "            <td>\n" +
                           "                <button type=\"submit\"><a href=\"${pageContext.request.contextPath}/btype/type_update?typeid="+element.typeid+"\">修改</a></button>\n" +
                           "            </td>\n" +
                           "            <td>\n" +
                           "                <button type=\"submit\" class=\"delbtn\">删除</button>\n" +
                           "            </td>\n" +
                           "        </tr>";
                       $("#tbody").append(tr);
                   });
                }
            });
        }


    </script>
    <style type="text/css">
        body {
            font-size: 20px;
            padding-bottom: 40px;
            background-color: #e9e7ef;
        }

        .sidebar-nav {
            padding: 9px 0;
        }

        @media ( max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
    </style>
</head>
<body>
<form class="form-inline definewidth m20" action="#" method="get">
    <font color="#777777"><strong>大类信息：</strong></font>

</form>
<table class="table table-bordered table-hover definewidth m10">
    <thead>
    <tr>
        <th>大类名称</th>
        <th>类别描述</th>
        <th>查看小类</th>
        <th>小类管理</th>
        <th>修改</th>
        <th>删除</th>
    </tr>
    </thead>
    <tbody id="tbody">


    </tbody>
</table>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<button type="button" id="addnew">
    <a href="${pageContext.request.contextPath}/btype/type_add">添加大类</a>
</button>
</body>
</html>